package com.hefei.rdd

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author caizhengjun
 * @date 2020/8/28 7:01 下午
 */
object Spark05_RDD_Aggregate {

  def main(args: Array[String]): Unit = {

    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName(this.getClass.getSimpleName)

    val sc: SparkContext = new SparkContext(conf)

    val valueRDD: RDD[(String, Int)] = sc.makeRDD(
      List(
        ("a", 1), ("a", 2), ("c", 3),
        ("b", 4), ("c", 5), ("c", 6)
      ), 2
    )

    val resultRDD = valueRDD.aggregateByKey(0)(Math.max, _ + _)

    println(resultRDD.collect().mkString(","))

    sc.stop()
  }
}
